//
//  FoodChoseViewController.swift
//  beegin2
//
//  Created by zsy on 16/3/6.
//  Copyright © 2016年 kszz. All rights reserved.
//

import UIKit

class FoodChoiseViewController: UIViewController ,UITextFieldDelegate{

    @IBOutlet weak var histScrollView:UIScrollView!
    @IBOutlet weak var backImageView:UIImageView!
    @IBOutlet weak var searchTextField:UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        //self.view.backgroundColor = UIColor(red: 1, green: 1, blue: 0.5, alpha: 0.5)
      //  self.view.backgroundColor = UIColor.clearColor()
        
        let ges = UITapGestureRecognizer(target: self, action: #selector(dismissKey(_:)))
        self.view.addGestureRecognizer(ges)        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewDidAppear(animated: Bool) {
        
        super.viewDidAppear(animated)
        
        initHistoryView([("content_img","苹果"),("content_img","苹果1234567892345633")])
        initZVScrollerSlider()
    }
    
    func initHistoryView(histArry:[(imageStr:String,histName:String)]){
    
        histScrollView.pagingEnabled = true
        histScrollView.showsHorizontalScrollIndicator = false;
        histScrollView.showsVerticalScrollIndicator = false;
        histScrollView.scrollsToTop = false;
        
        histScrollView.contentSize = CGSizeMake(histScrollView.frame.width * 3, 125);
        let histView = UIView(frame: CGRect(x: 0, y: 0, width:histScrollView.frame.width * 3, height: 125))
        
        for k in 0...histArry.count - 1{
        
            let button = UIButton(frame: CGRect(x: 0, y:0, width: 50, height: 50))
            let centerX:CGFloat = (1 / 2 + CGFloat(k) ) * histView.frame.width / 9
            let centerY:CGFloat = 50
            button.setImage(UIImage(named: histArry[k].imageStr), forState: .Normal)
            button.layer.cornerRadius = 25
            button.clipsToBounds = true
            button.layer.borderWidth = 0.4
            button.layer.borderColor = UIColor.whiteColor().CGColor
            histView.addSubview(button)
            button.center = CGPoint(x: centerX, y: centerY)
            
            let label = UILabel(frame: CGRect(x: 0, y: 0, width: histView.frame.width / 9.0 - 4, height: 25))
            label.textAlignment = .Center
            label.text = histArry[k].histName
            label.textColor = UIColor(red: 245 / 255, green: 247 / 255, blue: 255 / 255, alpha: 254 / 255)
            label.font = UIFont(name: "PingFang SC", size: 12)

            histView.addSubview(label)
            label.center = CGPoint(x: centerX, y: centerY + 42)
            
            
        }
        
        let hImageView = UIImageView(frame: CGRect(x: 0, y: 124, width: histView.frame.width, height: 0.5))
        hImageView.image = UIImage(named: "hist_h_line")
        histView.addSubview(hImageView)
        
        for k in 0...9{
            
            let vImageView = UIImageView(frame: CGRect(x: CGFloat(k) * histView.frame.width / 9.0, y: 0, width: 0.5, height: 124))
            vImageView.image = UIImage(named: "hist_v_line")
            
            histView.addSubview(vImageView)
        }
        
        histScrollView.addSubview(histView)
    }
    
    func initZVScrollerSlider(){
    
        let zvHeight = ZVScrollSlider.heightWithBoundingWidth(view.frame.width + 200, title: "abc")
        let zvScroll = ZVScrollSlider(frame: CGRect(x: -100, y: view.frame.height - 250, width: view.frame.width + 200, height: zvHeight ), title: "", minValue: 0, maxValue: 500, step: 1, unit: "kg", hasDeleteBtn: false)
        zvScroll.backgroundColor = UIColor.clearColor()
        view.addSubview(zvScroll)
    }

    @IBAction func btnOk(sender:AnyObject){

        self.dismissViewControllerAnimated(true, completion: nil)
    }
    
    
    // MARK: - Search textfield
    func textFieldShouldReturn(textField: UITextField) -> Bool {
        
        textField.resignFirstResponder()
        performSegueWithIdentifier("FoodShowIdentifer", sender: self)
        return true
    }
    func dismissKey(sender:AnyObject){
        
        
        searchTextField.resignFirstResponder()
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */


}
